//
//  MainViewController.swift
//  sinaWeibo
//
//  Created by wan on 15/12/14.
//  Copyright © 2015年 wan. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {
    //必选属性
    let mainTabBar = MainTabBar()

    
  @objc private func btnClick(){
    
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        mainTabBar.composeBtn.addTarget(self, action: "btnClick", forControlEvents: .TouchUpInside)
        setValue(MainTabBar(), forKey: "tabBar")
        
        //添加子视图控制器
        addChildViewControllers()
    }
    //private表示只能在本类中进行访问
    private func addChildViewControllers() {
      

        addChildViewController(HomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(MessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(DiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(ProfileTableViewController(), title: "我的", imageName: "tabbar_profile")

    }
    
    private func addChildViewController(vc:UIViewController,title: String,imageName: String
        ) {
            
            let nav = UINavigationController(rootViewController: vc)
            //        nav.title = "首页"
            vc.title = title
            //设置图片
            vc.tabBarItem.image = UIImage(named:imageName)
            //            vc.tabBarItem.selectedImage = UIImage(named: imageName + "_highlighted")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
//            vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)
            //在swift中 self 可以省略
            self.addChildViewController(nav)
    }
}
